<template>
  <van-goods-action>
    <van-goods-action-icon
      :icon="isCollected ? 'star' : 'star-o'"
      :text="isCollected ? '已收藏' : '收藏'"
      :color="isCollected ? '#ee0a24' : '#666'"
      @click="toCollected"
    />
    <van-goods-action-icon
      icon="cart-o"
      text="购物车"
      :badge="isLogin ? goodsNum : 0"
       @click="$router.push('/cart')"
    />
    <van-goods-action-button
      type="danger"
      text="立即购买"
     
    />
    <van-goods-action-button
      type="warning"
      text="加入购物车"
      @click="toAddcart"
    />
  </van-goods-action>
</template>

<script>
export default {
  props: ["goodsNum"],
  data() {
    return {
      isCollected: false,
      isLogin: false,
    };
  },
  created() {
    //判断有没登陆
    let token = localStorage.getItem("token");
    if (token) {
      this.isLogin = true;
    }
  },
  mounted() {},
  methods: {
    //收藏
    toCollected() {
      //先判断有没有登陆
      // let token=localStorage.getItem('token')
      // if(!token){
      //   this.$toast('请先登录!')
      //   setTimeout(()=>{
      //     this.$router.push('/user')
      //   },1000)
      //   return
      // }
      let ret = this.utils.mustBeLogin();
      if (!ret) return;
      this.isCollected = !this.isCollected;
    },
    //父传子
    toAddcart() {
      this.$emit("toAddcart");
    },
  },
};
</script>

<style scoped lang="less">
.van-goods-action {
  z-index: 9999;
}
</style>
